<script setup>
    import { onBeforeUnmount,ref } from "vue";
    import emitter from "../utils/bus";

    let message=ref("");

    //注册事件监听器 on('事件名',处理函数)
    emitter.on('sendDataTo1',(data) => {
        message.value=data.msg;
    });

    //在组件卸载之前进行必要的资源清理和状态管理，避免潜在的内存泄露
    onBeforeUnmount(() => {
        emitter.off('sendDataTo1') //移除事件监听器
    });
</script>

<template>
    <div>
        <h2>组件1</h2>
        <div>收到消息：{{ message }}</div>
    </div>
</template>